Ektron CMS400.Net Reference
Whenever your code is interacting with a widget, you need to verify that it is on a page builder page (as opposed to another Ektron CMS400.NET page that hosts widgets, such as personalization).
To check for this, insert the following code:
Ektron.Cms.PageBuilder.PageBuilder p = (Page as PageBuilder); If(p==null) // then this is not a wireframe When you want to check the mode, use code like this. If(p.status == Mode.Edit) // we are in edit mode